02 February, 2025

Domains in 23ai Schema Development

 I had heard of Data Use Case Domains in 23ai. However, the New Features nd Database Concepts documentation didn't provide enough examples for me to build on.

However, this blog post by Ulrike Schwinn  (which was shared by @thatjeffsmith  on X) helped me explore domains.

In this demo, I am using the Pre-Seeded Domains.  However, you can see the example posted by Ulrike Schwimm  or even read in the Database Concepts documentation  to help build your own custom Domains.

A Data Use Case Domain is like defining a Custom DataType such that only valid values are permitted.  The Domain name can be a self-identifier (just as "DATE" or "NUMBER" identifies the type of data being stored).

Here  is my demonstration  (I also use the Annotations feature -- the Data Use Case Domains documentation links above also lead to this feature)


SQL> set pages600 linesize 132
SQL> col contact_person format a32
SQL> col contact_email format a24
SQL>
SQL> drop table forex_rates_contacts;

Table dropped.

SQL>
SQL>
SQL> create table forex_rates_contacts
  2  (
  3   country_iso_code  varchar2(3) domain country_code_d,  -- preseeded SYS domain
  4   currency_code varchar2(3) domain currency_code_d, -- preseeded SYS domain
  5   contact_person varchar2(128),
  6   contact_email     varchar2(4000) domain email_d -- preseed SYS domain
  7  )
  8  annotations (display 'Forex Contact Persons')
  9  /

Table created.

SQL>
SQL> desc forex_rates_contacts
 Name                                                                     Null?    Type
 ------------------------------------------------------------------------ -------- -------------------------------------------------
 COUNTRY_ISO_CODE                                                                  VARCHAR2(3) SYS.COUNTRY_CODE_D
 CURRENCY_CODE                                                                     VARCHAR2(3) SYS.CURRENCY_CODE_D
 CONTACT_PERSON                                                                    VARCHAR2(128)
 CONTACT_EMAIL                                                                     VARCHAR2(4000) SYS.EMAIL_D

SQL>
SQL>
SQL> set long 1000
SQL> set longc 1000
SQL> set serveroutput on
SQL>
SQL> rem  FROM clause is no longer required in 23ai
SQL> select dbms_metadata.get_ddl('TABLE','FOREX_RATES_CONTACTS','HEMANT');

DBMS_METADATA.GET_DDL('TABLE','FOREX_RATES_CONTACTS','HEMANT')
------------------------------------------------------------------------------------------------------------------------------------

  CREATE TABLE "HEMANT"."FOREX_RATES_CONTACTS"
   (    "COUNTRY_ISO_CODE" VARCHAR2(3) DOMAIN "SYS"."COUNTRY_CODE_D",
        "CURRENCY_CODE" VARCHAR2(3) DOMAIN "SYS"."CURRENCY_CODE_D",
        "CONTACT_PERSON" VARCHAR2(128),
        "CONTACT_EMAIL" VARCHAR2(4000) DOMAIN "SYS"."EMAIL_D"
   ) SEGMENT CREATION DEFERRED
  PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255
 NOCOMPRESS LOGGING
  TABLESPACE "USERS"
  ANNOTATIONS("DISPLAY" 'Forex Contact Persons')


SQL>
SQL>
SQL>
SQL> rem  MULTI-ROW Insert
SQL> insert into forex_rates_contacts
  2  values
  3  ('US','USD','Mr Unknown','unknown@nowhere.gov'),
  4  ('IN','INR','Someone at RBI','someone@rbi.gov.in')
  5  /

2 rows created.

SQL>
SQL> commit;

Commit complete.

SQL>
SQL> select * from forex_rates_contacts
  2  order by country_iso_code
  3  /

COU CUR CONTACT_PERSON                   CONTACT_EMAIL
--- --- -------------------------------- ------------------------
IN  INR Someone at RBI                   someone@rbi.gov.in
US  USD Mr Unknown                       unknown@nowhere.gov

SQL>
SQL> -- Note that the country_code_d and currency_code_d do not check validity against really ISO codes
SQL> -- thus, it does not disallow "ZZ" and "ZZZ"
SQL> insert into forex_rates_contacts
  2  values
  3  ('ZZ','ZZZ','Mr Unknown','unknown@nowhere.zz')
  4  /

1 row created.

SQL>
SQL> select * from forex_rates_contacts
  2  order by country_iso_code
  3  /

COU CUR CONTACT_PERSON                   CONTACT_EMAIL
--- --- -------------------------------- ------------------------
IN  INR Someone at RBI                   someone@rbi.gov.in
US  USD Mr Unknown                       unknown@nowhere.gov
ZZ  ZZZ Mr Unknown                       unknown@nowhere.zz

SQL>
SQL> commit;

Commit complete.

SQL>
SQL> -- But the rules for email validation are encoded
SQL> insert into forex_rates_contacts
  2  values
  3  ('UK','GBP','Mr Someone','someone@x')
  4  /
insert into forex_rates_contacts
*
ERROR at line 1:
ORA-11534: check constraint (HEMANT.SYS_C0013464) involving column CONTACT_EMAIL due to domain constraint SYS.SYS_DOMAIN_C0030 of
domain SYS.EMAIL_D violated
Help: https://docs.oracle.com/error-help/db/ora-11534/


SQL>
SQL> select * from forex_rates_contacts
  2  order by country_iso_code
  3  /

COU CUR CONTACT_PERSON                   CONTACT_EMAIL
--- --- -------------------------------- ------------------------
IN  INR Someone at RBI                   someone@rbi.gov.in
US  USD Mr Unknown                       unknown@nowhere.gov
ZZ  ZZZ Mr Unknown                       unknown@nowhere.zz

SQL>
SQL> spool off


I haven't added my own custom Domains but used the PreSeeded domains for Country, Currency and Email.  Look at "10.1.12 Built-In Use Case Domains" in the documentation.



26 January, 2025

23ai New Feature : Partition HIGH_VALUE in JSON format

 A quick demonstration of the new HIGH_VALUE_JSON column in the USER_TAB_PARTITIONS view in 23ai :


[oracle@localhost Hemant]$ sqlplus hemant/hemant@freepdb1

SQL*Plus: Release 23.0.0.0.0 - for Oracle Cloud and Engineered Systems on Sun Jan 26 10:07:09 2025
Version 23.6.0.24.10

Copyright (c) 1982, 2024, Oracle.  All rights reserved.

Last Successful login time: Sun Jan 26 2025 10:05:18 +00:00

Connected to:
Oracle Database 23ai Free Release 23.0.0.0.0 - Develop, Learn, and Run for Free
Version 23.6.0.24.10

SQL> @demo_part_high_value.sql
SQL> set pages600 linesize 132
SQL> set long 10000
SQL>
SQL> spool demo_part_high_value
SQL>
SQL> -- 23ai has two new columns in the USER_TAB_PARTTIIONS view
SQL> -- HIGH_VALUE_CLOB and     HIGH_VALUE_JSON
SQL> --- unlike HIGH_VALUE which is a LONG, these two can be used programmatically
SQL> -- here I show HIGH_VALUE_JSON along with the HIGH_VALUE
SQL>
SQL> set pages600 linesize 132
SQL> set long 10000
SQL> col partition_name format a8 hea 'P_Name'
SQL> col high_value format a56 trunc hea 'High_Value_LONG' trunc
SQL> col high_value_json format a48 hea 'High_Value_JSON'
SQL>
SQL>
SQL> drop table hkc_test_intvl;

Table dropped.

SQL>
SQL> create table hkc_test_intvl
  2  (date_column date,
  3  data_column varchar2(50))
  4  partition by range (date_column)
  5  interval (numtoyminterval(1,'MONTH'))
  6  (partition P_1 values less than (to_date('01-FEB-2024','DD-MON-YYYY')))
  7  /

Table created.

SQL>
SQL>
SQL> insert into hkc_Test_intvl
  2  values (to_date('15-AUG-2024','DD-MON-YYYY'), 'August Row')
  3  /

1 row created.

SQL>
SQL>
SQL> insert into hkc_test_intvl
  2  values (to_date('15-OCT-2024','DD-MON-YYYY'),'October Row')
  3  /

1 row created.

SQL>
SQL> insert into hkc_test_intvl
  2  values (to_date('15-DEC-2024','DD-MON-YYYY'),'December Row')
  3  /

1 row created.

SQL>
SQL> select partition_name, high_value,  high_value_json
  2  from user_tab_partitions
  3  where table_name = 'HKC_TEST_INTVL'
  4  /

P_Name   High_Value_LONG                                          High_Value_JSON
-------- -------------------------------------------------------- ------------------------------------------------
P_1      TO_DATE(' 2024-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS' {"high_value":"2024-02-01T00:00:00"}
SYS_P447 TO_DATE(' 2024-09-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS' {"high_value":"2024-09-01T00:00:00"}
SYS_P448 TO_DATE(' 2024-11-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS' {"high_value":"2024-11-01T00:00:00"}
SYS_P449 TO_DATE(' 2025-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS' {"high_value":"2025-01-01T00:00:00"}

SQL>
SQL>
SQL> spool off


Earlier, HIGH_VALUE was presented as a LONG.
23ai adds two columns to the USER_TAB_PARTITIONS data dictionary view :
HIGH_VALUE_CLOB
and 
HIGH_VALUE_JSON

These make it easier to query the data dictionary, for example, for Partition Life Cycle management.